<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
<link href="/resource/css/bootstrap.css" rel="stylesheet">

<script type="text/javascript" src="/resource/js/jquery-3.4.1.js"></script>
<script type="text/javascript" src="/resource/js/bootstrap.js"></script>
<script type="text/javascript" src="/resource/js/bootstrap-treeview.js"></script>
<script type="text/javascript"> 
$(function(){
	$.get("/getBrands",function(list){
		for(var i in list){//品牌
			$("#bid").append("<option  value='"+list[i].bid+"'>"+list[i].bname+"</option>")
		}
		//让下来框回显
		$("#bid").val('${goods.brandId}')
	})
	
	
	$.get("/getProducts",function(list){
		for(var i in list){//分类
			$("#pid").append("<option  value='"+list[i].pid+"'>"+list[i].pname+"</option>")
		}
		//让下来框回显
		$("#pid").val('${goods.productId}')
	})
	
})
//分页
function goPage(pageNum){
	$("#pageNum").val(pageNum);
	$("form").submit()
}

//删除
function deleteById(id){
	if(confirm("确实删除吗？")){
		$.post("/deleteById",{id:id},function(flag){
			if(flag){
				alert("删除成功");
				location.href="/list"
			}
		})
		
		
	}
	
}
//搜索
function search(){
	var value=$.trim($("#value").val());
	if(value==''){
		alert("请输入要搜索的值");
		return ;
	}
	location.href="/search?value="+value
}
</script>
</head>
<body>
 <div>
 
 <a href="/getTrailTotal">查看操作轨迹统计</a>
  <a href="/getTraiInfo?minute=3">查看操作3分钟内轨迹</a>
  <div >
  <form action="/list">
  <input id="pageNum" type="hidden" name="pageNum">
   商品名称:<input id="value"  type="text" name="goodsName" value="${goods.goodsName }"> 
  品牌： <select id="bid" name="brandId">
    <option></option>
   </select>
   品类： <select id="pid" name="productId">
      <option></option>
   </select>
  <button type="submit" class="btn btn-info">查询</button>
  
    <button type="button" class="btn btn-success" onclick="search()">按商品搜索</button>
  
  </form>
  </div>
 
 </div>
	<table class="table">
		<tr>
			<td>商品ID</td>
			<td>商品名称</td>
			<td>商品品牌</td>
			<td>商品品类</td>
			<td>操作    <a href="/add">增加</a></td>

		</tr>

		<c:forEach items="${info.list}" var="goods">
			<tr>
				<td>${goods.id }</td>
				<td>${goods.goodsName }</td>
				<td>${goods.bname }</td>
				<td>${goods.pname}</td>
				<td><a href="/update?id=${goods.id }">修改 </a>|<button type="button" onclick="deleteById('${goods.id}')"> 删除 </button></td>
			</tr>


		</c:forEach>

	</table>
	<jsp:include page="/resource/page/pages.jsp"></jsp:include>
</body>
</html>